package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.SchoolMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.School;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.SchoolExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchoolServiceImpl implements ISchoolService {
    @Autowired
    private SchoolMapper schoolMapper;
    @Override
    public int insertSchool(School school) {
        return schoolMapper.insert(school);
    }

    @Override
    public List<School> queryAllSchool() {
        List<School> schools = schoolMapper.selectAll();
        return schools;
    }

    @Override
    public List<School> querySchoolPage(int pageNow,int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<School> schools = schoolMapper.selectAll();
        PageInfo<School> schoolPageInfo = new PageInfo<>(schools);
        return schoolPageInfo.getList();
    }

    @Override
    public int queryTotalSchoolCount() {
        SchoolExample schoolExample = new SchoolExample();
        SchoolExample.Criteria criteria = schoolExample.createCriteria();
        criteria.getAllCriteria();
        return (int) schoolMapper.countByExample(schoolExample);
    }

    @Override
    public School querySchoolById(Integer id) {
        return schoolMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteSchoolById(Integer id) {
        return schoolMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateSchoolById(School school) {
        return schoolMapper.updateByPrimaryKey(school);
    }
}
